

const sha1 = require('js-sha1')

const config = require('../utils/wxConfig.js')


module.exports = ctx => {
	var token = config.wechat.token;
	var signature = ctx.query.signature;
	var nonce = ctx.query.nonce;
	var timestamp = ctx.query.timestamp;
	var echostr = ctx.query.echostr;
	var sha = sha1([token,timestamp,nonce].sort().join(''));
   ctx.body = (sha === signature)? echostr + '' : 'failed';
}